package cn.edu.sctu.sctu_lysd.utils;

import android.animation.ValueAnimator;
import android.app.Activity;
import android.view.WindowManager;
import android.view.animation.LinearInterpolator;

/**
 * Created by wangfuxin on 2017-04-14.
 */

public class LightUtils {


    /**
     * 内容区域变亮
     */
    public static void lightOn(final Activity mActivity) {
        final WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();

        /**
         * 值动画
         */
        ValueAnimator valueAnimator = new ValueAnimator().ofFloat(0.3f, 1.0f);
        valueAnimator.setDuration(1000);
        valueAnimator.setInterpolator(new LinearInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                lp.alpha = (float) animation.getAnimatedValue();
                mActivity.getWindow().setAttributes(lp);
            }
        });

        valueAnimator.start();
    }

    /**
     * 内容区域变暗
     */
    public static void lightOff(final Activity mActivity) {

        final WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();

        /**
         * 值动画
         */
        ValueAnimator valueAnimator = new ValueAnimator().ofFloat(1.0f, 0.3f);
        valueAnimator.setDuration(500);
        valueAnimator.setInterpolator(new LinearInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                lp.alpha = (float) animation.getAnimatedValue();
                mActivity.getWindow().setAttributes(lp);
            }
        });

        valueAnimator.start();

        mActivity.getWindow().setAttributes(lp);
    }


}
